﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.ComponentModel;

namespace GameProject.ViewModel
{
    class ViewModelBase : INotifyPropertyChanged
    {

        public event PropertyChangedEventHandler PropertyChanged;

        protected virtual void onPropertyChanged(String PropertyName)
        {
            this.verifyPropertyName(PropertyName);

            PropertyChangedEventHandler handler = this.PropertyChanged;

            if (handler != null)
            {
                var e = new PropertyChangedEventArgs(PropertyName);
                handler(this, e);
            }
        }


        public void verifyPropertyName(String PropertyName)
        {
            if (TypeDescriptor.GetProperties(this)[PropertyName] == null)
            {
                string msg = "Invalid Propertyname : " + PropertyName;
                throw new Exception(msg);
            }
        }

    }
}
